import { select } from '@/api/system/dict'

const state = {
  boolean_select: [{ label: '是', value: true }, { label: '否', value: false }],

  system_notice_type: [],
  system_log_type: [],
  system_file_tag: [],
  system_user_state: [],
  system_faq_type: [],

  // 单位
  escm_unit: [],
  // 产地
  escm_origin_country: [],
  // 币制
  escm_curreny: [],
  // 收货方式
  escm_receiving_mode: [{ label: '客户自提', value: 1 }, { label: '华富洋送货', value: 2 }, { label: '第三方物流', value: 3 }],
  // 交货类型
  escm_delivery_type: [{ label: '单个交货点', value: 1 }, { label: '多个交货点', value: 2 }],
  // 发运要求
  escm_shipping_requirement: [{ label: '时效优先', value: 1 }, { label: '费用优先', value: 2 }],
  // 境外快递运营商
  escm_overseas_expresss_company: [],
  // 国内第三方运营商
  escm_express_company: [],
  // 自营承运商
  escm_self_express_company: [],
  // 送货方式
  escm_delivery_mode: [{ label: '送货上门', value: 1 }, { label: '客户自提', value: 2 }],
  // 费用区间
  escm_cost_range: [],
  // 省
  escm_province: []
}

const mutations = {
  DICT_SELECT: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}

const actions = {
  GetDictByDictType({ commit }, dictType) {
    return new Promise((resolve, reject) => {
      select(dictType).then(res => {
        commit('DICT_SELECT', { key: dictType, value: res })
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
